/*
 * MANSCDP.h
 *
 *  Created on: 2015年7月11日
 *      Author: chuanjiang.zh@qq.com
 */

#ifndef VGS_MANSCDP_H_
#define VGS_MANSCDP_H_

#include "BasicType.h"
#include <string>
#include <vector>



namespace gb
{

extern const char* MIME_APPLICATION;
extern const char* MIME_MANSCDP_SUBTYPE;

extern const char* MIME_MANSCDP;
extern const char* MIME_SDP;

extern const char*  CONTROL;
extern const char*  QUERY;
extern const char*  NOTIFY;
extern const char*  RESPONSE;

extern const char*  CmdType;
extern const char*  SN;

extern const char* ONLINE;
extern const char* OFFLINE;


struct Command
{
    std::string m_class;    /// 消息分类, control, query, notify, response
    std::string m_type;     ///
    int m_sn;
    std::string m_deviceID;
    //std::string m_name;

    Command()
    {
        m_sn = 0;
    }
};


struct Request : public Command
{
    std::string m_name;

    Request()
    {
        m_class = CONTROL;
    }
};


struct Response : public Command
{
    std::string  m_result;

    Response()
    {
        m_class = RESPONSE;
    }

    explicit Response(const Request& obj)
    {
        m_class = RESPONSE;
        copy(obj);
    }

    void copy(const Request& req)
    {
        m_type = req.m_type;
        m_sn = req.m_sn;
        m_deviceID = req.m_deviceID;
    }

};

struct Query : public Command
{
    Query()
    {
        m_class = QUERY;
    }
};

struct Notify : public Command
{
    Notify()
    {
        m_class = NOTIFY;
    }
};


int makeSN();

std::string makeSNStr();

void fillSN(Request& req);




/**
 * PTZ控制请求
 */
struct PtzRequest : public Request
{
    std::string  m_ptzCmd;
    int m_priority;

    PtzRequest():
        Request(),
        m_ptzCmd(),
        m_priority()
    {
        m_type = "DeviceControl";
    }
};

/**
 * 重启请求
 */
struct DeviceBootRequest : public Request
{
    DeviceBootRequest():
        Request()
    {
        m_type = "DeviceControl";
    }
};

/**
 * 录像请求
 */
struct DeviceRecordRequest : public Request
{
    std::string  m_recordCmd;

    DeviceRecordRequest():
        Request(),
        m_recordCmd()
    {
        m_type = "DeviceControl";
    }
};

/**
 * 布防/撤防请求
 */
struct GuardRequest: public Request
{
    std::string  m_guardCmd;

    GuardRequest():
        Request(),
        m_guardCmd()
    {
        m_type = "DeviceControl";
    }
};

/**
 * 告警重置请求
 */
struct AlarmResetRequest : public Request
{
    AlarmResetRequest():
        Request()
    {
        m_type = "DeviceControl";
    }
};

/**
 * 设备状态查询
 */
struct DeviceStatusRequest: public Request
{
    DeviceStatusRequest():
        Request()
    {
        m_type = "DeviceStatus";
    }
};

/**
 * 设备目录查询, 用于订阅
 */
struct CatalogQuery: public Query
{
    std::string m_startTime;
    std::string m_stopTime;

    CatalogQuery()
    {
        m_type = "Catalog";
    }

};

/**
 * 设备信息查询
 */
struct DeviceInfoQuery: public Query
{
    DeviceInfoQuery()
    {
        m_type = "DeviceInfo";
    }
};

/**
 * 录像查询
 */
struct RecordInfoQuery: public Query
{
    time_t  m_startTime;
    time_t  m_endTime;
    std::string  m_filePath;
    std::string  m_address;
    int     m_secrecy;
    std::string  m_class;
    std::string  m_recorderID;

    RecordInfoQuery():
        m_startTime(),
        m_endTime(),
        m_filePath(),
        m_address(),
        m_secrecy(),
        m_class(),
        m_recorderID()
    {
        m_type = "RecordInfo";
    }
};

/**
 * 告警查询
 */
struct AlarmQuery: public Query
{
    int     m_startAlarmPriority;
    int     m_endAlarmPriority;
    std::string  m_alarmMethod;
    time_t  m_startTime;
    time_t  m_endTime;

    AlarmQuery():
        m_startAlarmPriority(),
        m_endAlarmPriority(),
        m_alarmMethod(),
        m_startTime(),
        m_endTime()
    {
        m_type = "Alarm";
    }
};

/**
 * 设备状态报送
 */
struct KeepaliveNotify : public Notify
{
    std::string  m_status;

    KeepaliveNotify():
        m_status()
    {
        m_type = "Keepalive";
    }
};

/**
 * 告警通知
 */
struct AlarmNotify : public Notify
{
    int     m_priority;
    std::string m_time;
    std::string  m_method;
    std::string  m_desc;
    double  m_longitude;
    double  m_latitude;

    AlarmNotify():
        Notify(),
        m_priority(),
        m_time(),
        m_method(),
        m_longitude(),
        m_latitude()
    {
        m_type = "Alarm";
    }
};

struct BroadcastNotify : public Notify
{
	std::string m_sourceID;
	std::string m_targetID;

	BroadcastNotify()
	{
		m_type = "Broadcast";
	}


};


struct DeviceControlResponse : public Response
{
    DeviceControlResponse():
        Response()
    {
        m_type = "DeviceControl";
    }
};


struct AlarmNotifyResponse: public Response
{
    AlarmNotifyResponse():
        Response()
    {
        m_type = "Alarm";
    }
};


struct DeviceItem
{
    std::string  m_deviceID;
    std::string  m_name;
    std::string  m_manufacture;
    std::string  m_model;

    std::string  m_owner;
    std::string  m_civilCode;
    std::string  m_block;
    std::string  m_address;
    std::string  m_parental;

    std::string  m_parentID;

    std::string m_ip;
    int     m_port;
    std::string m_password;
    std::string m_status;

    double  m_longitude;
    double  m_latitude;

    DeviceItem():
        m_deviceID(),
        m_parentID(),
        m_ip(),
        m_port(),
        m_longitude(),
        m_latitude()
    {

    }

};

typedef std::vector< DeviceItem >   DeviceList;

struct CatalogItem
{
	std::string m_deviceID;
	std::string m_name;
	std::string m_parentID;
	std::string m_address;
	std::string m_status;
	std::string m_longitude;
	std::string m_latitude;
};

struct CatalogResponse: public Response
{
    int m_sumNum;
    DeviceList  m_itemList;

    CatalogResponse():
        Response(),
        m_sumNum()
    {
        m_type = "Catalog";
    }
};


struct AlarmDeviceStatus
{
    std::string m_deviceID;
    std::string m_status;
};

typedef std::vector< AlarmDeviceStatus >    AlarmDeviceStatusList;

struct DeviceStatusResponse : public Response
{
    std::string  m_online;
    std::string  m_status;
    std::string  m_encode;
    std::string  m_record;
    std::string  m_time;

    //AlarmDeviceStatusList m_arrAlarmStatus;

    DeviceStatusResponse():
        Response(),
        m_online(),
        m_status()
    {
        m_type = "DeviceStatus";
    }


};

struct DeviceInfoResponse: public Response
{
    std::string  m_devType;
    std::string  m_manufacturer;
    std::string  m_model;
    std::string  m_firmware;
    int m_maxCamera;
    int m_maxAlarm;

    DeviceInfoResponse():
        m_manufacturer(),
        m_model(),
        m_firmware(),
        m_maxCamera(),
        m_maxAlarm()
    {
        m_type = "DeviceInfo";
    }

};







} /* namespace gb */

#endif /* VGS_MANSCDP_H_ */
